package com.alisls.demo.springcloud.oauth.server.web;

import com.alisls.demo.springcloud.common.model.dto.DataResult;
import com.alisls.demo.springcloud.common.model.dto.Result;
import com.alisls.demo.springcloud.oauth.server.dto.OAuthClientDetailDTO;
import com.alisls.demo.springcloud.oauth.server.dto.OAuthClientDetailPwdDTO;
import com.alisls.demo.springcloud.oauth.server.service.OAuthClientDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 描述信息
 *
 * @author Ke Wang
 * @date 2020/10/31
 */
@Api(tags = "OAuth客户端管理", description = "提供对OAuth客户端的CRUD接口")
@RestController
@RequestMapping("/oAuthClientDetail")
@AllArgsConstructor
public class OAuthClientDetailController {

    private final OAuthClientDetailService oAuthClientDetailService;

    @ApiOperation(value = "查询OAuth客户端", notes = "根据ClientId查询OAuth客户端")
    @GetMapping("/getByClientId/{clientId}")
    public Result getByClientId(@PathVariable String clientId) {
        OAuthClientDetailDTO oAuthClientDetailDTO = oAuthClientDetailService.getByClientId(clientId);
        return DataResult.ofSuccess(oAuthClientDetailDTO);
    }

    @ApiOperation(value = "保存OAuth客户端", notes = "保存OAuth客户端信息")
    @PostMapping("/save")
    public Result save(@RequestBody @Validated OAuthClientDetailPwdDTO oAuthClientDetailPwdDTO) {
        oAuthClientDetailService.save(oAuthClientDetailPwdDTO);
        return DataResult.ofSuccess(oAuthClientDetailPwdDTO);
    }

    @ApiOperation(value = "删除OAuth客户端", notes = "根据ClientId删除OAuth客户端")
    @GetMapping("/removeById/{clientId}")
    public Result removeById(@PathVariable String clientId) {
        Integer num = oAuthClientDetailService.remove(clientId);
        return DataResult.ofSuccess(num);
    }

}